
class Parameter
  def initialize(file_name)
    @file_name = file_name
    @parameter_hash = Hash.new

    file = open(file_name, "r")
    file.each_line do |line|
      key, val = line.split("=").map{|v| v.strip}
      @parameter_hash[key] = val
    end
    file.close
  end

  def init_as_component(component_manager)
    @component_manager = component_manager
  end


  def get(key)
    return @parameter_hash[key]
  end

  def set(key, val)
    @parameter_hash[key] = val
  end

  def save
    file = open(@file_name, "w")
    @parameter_hash.each_pair do |key, val|
      file.puts "#{key} = #{val}\n"
    end
    file.close
  end

  # test func
  def to_s
    result = ""
    @parameter_hash.each_pair do |key, val|
      result << "#{key} = #{val}\n"
    end
    return result
  end
end
